<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title></title>
    <%@ include file="/WEB-INF/views/modules/book/easyui.jsp"%>
</head>
<body style="font-family: '微软雅黑'">
<div id="tb" style="padding:5px;height:auto">
    <div>
        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-add" onclick="add();">添加</a>
        <span class="toolbar-item dialog-tool-separator"></span>
        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-remove" onclick="del()">删除</a>
        <span class="toolbar-item dialog-tool-separator"></span>
        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-edit" onclick="upd()">修改</a>
    </div>
</div>
<table id="dg"></table>

<div id="dlg"></div>
<div id="icon_dlg"></div>

<script type="text/javascript">
    var dg;
    var d;
    var permissionDg;
    var parentPermId;
    $(function(){
        dg=$('#dg').treegrid({
            method: "get",
            url:'${ctx}/book/bktype/json',
            fit : true,
            fitColumns : true,
            border : true,
            idField : 'id',
            treeField:'typDisn',
            parentField : 'pid',
            animate:false,
            rownumbers:false,
            singleSelect:true,
            striped:false,
            columns:[[
                {field:'id',title:'id',hidden:true,width:5},
                {field:'typName',title:'分类代码',width:8},
                {field:'typDisn',title:'分类名称',width:100}
            ]],
            enableHeaderClickMenu: false,
            enableHeaderContextMenu: false,
            enableRowContextMenu: false,
            toolbar:'#tb',
            dataPlain: true
        });

    });

    //弹窗增加
    function add() {
        //父级权限
        var row = dg.treegrid('getSelected');
        if(row){
            parentPermId=row.id;
        }
        d=$('#dlg').dialog({
            title: '添加书籍分类',
            width: 450,
            height: 320,
            closed: false,
            cache: false,
            maximizable:true,
            resizable:true,
            href:'${ctx}/book/bktype/create',
            modal: true,
            buttons:[{
                text:'确认',
                handler:function(){
                    $("#mainform").submit();
                }
            },{
                text:'取消',
                handler:function(){1

                    d.panel('close');
                }
            }]
        });
    }

    //删除
    function del(){
        var row = dg.treegrid('getSelected');

        if(rowIsNull(row)) return;

        $.messager.alert('提示', '删除后无法恢复您确定要删除？',"warning", function(){


                $.ajax({
                    type:'POST',
                    url:"${ctx}/book/bktype/delete?id="+row.id,
                    success: function(data){
                        if("success"==data){
                            dg.treegrid('reload');
                            $.messager.alert("操作提示", "删除成功","info");

                        }else{

                            $.messager.alert("操作提示", "删除失败，该分类被占用","warning");

                        }

                    }
                });
        });

    }

    //修改
    function upd(){
        var row = dg.treegrid('getSelected');
        if(rowIsNull(row)) return;
        //父级权限
        parentPermId=row.pid;
        d=$("#dlg").dialog({
            title: '修改分类',
            width: 450,
            height: 320,
            href:'${ctx}/book/bktype/update/'+row.id,
            maximizable:true,
            modal:true,
            buttons:[{
                text:'确认',
                handler:function(){
                    $("#mainform").submit();
                }
            },{
                text:'取消',
                handler:function(){
                    d.panel('close');
                }
            }]
        });

    }

    var nowIcon;
    var icon_dlg;
</script>
</body>
</html>